package me.leiusual.sharing.ui.order.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_order_detail_invoice.*
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.orderdetail.Invoice
import me.leiusual.sharing.util.extension.toSpanned

/**
 * author: leiusual
 * create on: 2019-08-11
 * description:
 */
class OrderDetailInvoiceViewHolder(
    override val containerView: View,
    private val clickListener: (Invoice) -> Unit
) : RecyclerView.ViewHolder(containerView), LayoutContainer, View.OnClickListener {

  private lateinit var invoice: Invoice

  init {
    button_logistics.setOnClickListener(this)
  }

  fun bind(invoice: Invoice) {
    this.invoice = invoice

    val builder = StringBuilder()
    builder.append(invoice.deliveryAddress)
    builder.append("""<br/>${invoice.expressCompany}""")
    builder.append("""<br/>${invoice.expressNumber}""")
    text_view.text = builder.toString().toSpanned()
  }

  override fun onClick(v: View?) {
    when (v?.id) {
      R.id.button_logistics -> {
        clickListener(invoice)
      }
    }
  }
}